﻿using System;
using DiagnosticExplorer;

namespace Streambolics.App.Gpl
{
    public class DiagExObserver : ComputingModule
    {
        protected override void DoStart ()
        {
            RegisterObservedObjects ();
            ObservableObjects.ObjectAdded += new EventHandler<ObservableObjectEventArgs> (ObservableObjects_ObjectAdded);
            DeclareStarted ();
        }

        void ObservableObjects_ObjectAdded (object sender, ObservableObjectEventArgs e)
        {
            DiagnosticManager.Register (e.ObservableObject.Target, e.ObservableObject.Name, e.ObservableObject.Category);
        }

        protected override void DoStop ()
        {
            ObservableObjects.ObjectAdded -= new EventHandler<ObservableObjectEventArgs> (ObservableObjects_ObjectAdded);
            DeclareStopped ();
        }

        private void RegisterObservedObjects ()
        {
            foreach (ObservableObject o in ObservableObjects.All)
            {
                DiagnosticManager.Register (o.Target, o.Name, o.Category);
            }
        }
    }
}
